/**
 * Bid index JavaScript.
 */
var table = null;

//刷新表格
function dataTableReload2() {
    $('#winBidTable').dataTableExtend("reloadFalse");
}

function dataTableReload() {
    table.ajax.reload();
}

//投标详情弹出层
function openDetailPage(id) {

    DGG.Layer.open(sysInfo.basePath + "/sc/general/bid/detail.do?id=" + id, {
        title: '投标详情',
        area: ['80%', '80%'],
        btn: '关闭'
    });
}

// 获取搜索数据
function getSearchData() {
    return $.extend({}, $('.titleSearch').serializeJson());
}

/**
 * 导出
 * @returns
 */
function export_data() {
    export_table('/sc/general/bid/winExport.do', getSearchData());
}

/**
 * 初始化表格数据
 * @returns
 */
$(document).ready(function () {
    Plug.plug_in("post", sysInfo.basePath + "/sc/general/com/tree_book_list.do?code=BUS_YT&&type=2&&level=2", "#business_typeCode", '选择业态', '', true, 'BUS_YT', '', '');
    table = $('#winBidTable').dataTableExtend({
        "ajax": {"url": sysInfo.basePath + "/sc/general/bid/queryWinBidPage.do", "type": "post"},
        "fnServerParams": function (aoData) {
            aoData = $.extend(aoData, $('.titleSearch').serializeJson());
            return aoData;
        },
        "scrollX": "true",//是否开启横项滚动
        "fixedColumns": {//锁定列，只有开启scrollX时才生效
            "leftColumns": 0,//左侧锁定2列
            "rightColumns": 0//右侧锁定1列
        },
        "aoColumns": [
            {
                "orderable": false,
                "data": "id",
                "render": function (data, type, full, meta) {
                    return '<input type="checkbox"  name="ids" class="checkchild"  value="' + data + '" />';
                }
            }
            , {
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                }
            }, {
                "orderable": false,
                "data": "scProductOrderNo",
                "render": function (data, type, full, meta) {
                    return '<a href="javascript:;"  class="layui-table-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><p>' + data + '</p></a>';
                }
            }, {
                "orderable": false,
                "data": "scOrderNo",
                "render": function (data, type, full, meta) {
                    return '<a href="javascript:;"  class="layui-table-link" onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><p>' + data + '</p></a>';
                }
            }, {
                "orderable": false,
                "data": "customerName",
                "render": function (data, type, full, meta) {
                    return data ? data + "</br>" + full.customerPhone : '';
                }
            }, {
                "orderable": false,
                "data": "businessTypeId",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            }, {
                "orderable": false,
                "data": "businessProductId",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "orderable": false,
                "data": "productNames",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "orderable": false,
                "data": "signUserName",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }

            },
            {
                "orderable": false,
                "data": "signUserOrgName",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            }, {
                "orderable": false,
                "data": "flowUserName",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "orderable": false,
                "data": "bidOrRobTime",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "orderable": false,
                "data": "bidderNum",
                "render": function (data, type, full, meta) {
                    return data ? data : 0;
                }
            }, {
                "orderable": false,
                "data": "id",
                "render": function (d, type, r, meta) {
                    var result = "";
                    result += '<a href=\'javascript:void(0)\' ti  onclick="openDetailPage(\'' + r.id + '\')" /><span style="color: #0066ff ">投标详情</a>';
                    return result;
                }
            }],
        "columnDefs": [{
            targets: [0],
            createdCell: function (td, cellData, rowData, row, col) {
                var nodeSt = rowData.nodeultratime;
                var orderSt = rowData.productultratime;
                if (nodeSt == "OVERDUE_STATE2") {
                    $(td).parent().addClass(" bgOver")
                }
                if (orderSt == "OVERDUE_STATE2") {
                    $(td).parent().removeClass("bgOver").addClass(" bgRed")
                }
            }
        }]
    });


    $('.title-tab').on('click', 'a', null, function () {
        var $this = $(this);
        var status = $this.attr('data-status');
        $('#statusArr').val(status);
        var href = window.location.href;
        if (href.indexOf('status=') > -1) {
            href = href.substring(0, href.indexOf('status=') - 1);
        }
        window.location.href = href + (href.indexOf('?') > -1 ? '&' : '?') + 'status=' + status;
    });
});

/**
 * 时间格式化
 * @param time
 * @returns
 */
function timeStamp2String(time) {
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}